package xReseau;

import java.util.List;
import java.util.Set;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import xGraphique.xFenetrage.XFenetrePrincipale;
import xGraphique.xFenetrage.xMenu.xPlanches.XPlancheAffichageItineraire;
import xGraphique.xFenetrage.xMenu.xPlanches.XPlancheSaisieItineraireVilles;

@XmlRootElement(name = "PathResponse")
public class PathResponse implements IResponse {
	@SuppressWarnings("unused")
	@XmlElement(name = "troncon")
	private final List<Section> sectionList = null;

	@SuppressWarnings("unused")
	@XmlElement(name = "UnreachableCity")
	private final Set<City> unreachableCities = null;

	@SuppressWarnings("unused")
	@XmlElement(name = "NoAdmissiblePathFoundException")
	private final NoAdmissiblePathFoundExceptionXMLHandler noAdmissiblePathFoundException = null;

	public PathResponse() {
	}

	public boolean possiblePath() {
		if (sectionList == null || sectionList.size() == 0) {
			return false;
		}
		return true;
	}

	@XmlTransient
	public Set<City> getCitiesUnreachable() {
		return unreachableCities;
	}

	@XmlTransient
	public List<Section> getListSection() {
		return sectionList;
	}

	public void afficher() {
		System.out.println("\nAffichage du PathResponse :");
		if (sectionList != null) {
			System.out.println("troncons :");
			for (Section section : sectionList) {
				System.out.println(section);
				if (section.getContraintes() != null) {
					System.out.println(" Constraints violated :");
					for (ConstraintViolated constraint : section
							.getContraintes()) {
						System.out.println(" -" + constraint);
					}
				}
				System.out.println();
			}
		}
		if (unreachableCities != null) {
			System.out.println("Unreachable Cities :");
			for (City city : unreachableCities) {
				System.out.println(city);
			}
		}
		if (noAdmissiblePathFoundException != null) {
			System.out.println("NoAdmissiblePathFoundException : ");
			System.out.println(noAdmissiblePathFoundException);
		}
	}

	public boolean doResponse() {

		System.out.println("AFFICHER LE PATHRESPONSE");

		if (XPlancheAffichageItineraire.getInstance().setPathResponse(this)) {
			XFenetrePrincipale.getInstance().setPlanche(
					XPlancheAffichageItineraire.getInstance());
		} else {
			XFenetrePrincipale.getInstance().conteneurCarte.gatc.dessin
					.reinitialiser(false);
			XFenetrePrincipale.getInstance().setPlanche(
					XPlancheSaisieItineraireVilles.getInstance());
		}

		afficher();

		return true;
	}

}
